package com.cq.hd.common.response;

import com.cq.hd.common.enums.ExceptionEnum;
import com.cq.hd.common.enums.ResponseEnums;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @description: 包装返回实体类
 * @author: mYunYu
 * @date: 2021/7/7 15:48
 * @version: v1.0
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ResultGenerator {
    public static <E> Result<E> success() {
        return new Result<>(ResponseEnums.SUCCESS.getCode(), ResponseEnums.SUCCESS.getMessage());
    }

    public static <E> Result<List<E>> success(List<E> list) {
        return new Result<>(ResponseEnums.SUCCESS.getCode(), ResponseEnums.SUCCESS.getMessage(), list);
    }

    public static <E> Result<E> success(E data) {
        return new Result<>(ResponseEnums.SUCCESS.getCode(), ResponseEnums.SUCCESS.getMessage(), data);
    }

    public static Result<String> successOfString(String data) {
        return new Result<>(ResponseEnums.SUCCESS.getCode(), ResponseEnums.SUCCESS.getMessage(), data);
    }

    public static <E> Result<E> success(String message, E data) {
        return new Result<>(ResponseEnums.SUCCESS.getCode(), message, data);
    }

    public static <E> Result<E> success(Integer code, String message) {
        return new Result<>(code, message);
    }

    public static <E> Result<E> fail(ExceptionEnum exceptionEnum, E data) {
        return new Result<>(exceptionEnum.getCode(), exceptionEnum.getMsg(), data);
    }

    public static <E> Result<E> error() {
        return new Result<>(ResponseEnums.ERROR.getCode(), ResponseEnums.ERROR.getMessage());
    }

    public static <E> Result<E> error(String message) {
        return new Result<>(ResponseEnums.ERROR.getCode(), message);
    }

    public static <E> Result<E> error(int code, String message, E data) {
        return new Result<>(ResponseEnums.ERROR.getCode(), ResponseEnums.ERROR.getMessage(), data);
    }

    public static <E> Result<E> error(ResponseEnums responseEnums, E data) {
        return new Result<>(responseEnums.getCode(), responseEnums.getMessage(), data);
    }

    public static <E> Result<E> error(int code, String message) {
        return new Result<>(code, message);
    }

    public static <E> Result<E> error(ResponseEnums responseEnums) {
        return new Result<>(responseEnums.getCode(), responseEnums.getMessage());
    }

}
